package com.burgess.app;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class CvsHelper {

    public static List<TemplateBean> read(String filePath) {
        File csv = new File(filePath);  // CSV文件路径
        InputStreamReader isr = null;
        BufferedReader br = null;
        List<TemplateBean> returnList = null;
        try {
            isr = new InputStreamReader(new FileInputStream(csv), "GB18030");
            br = new BufferedReader(isr);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String line = "";
        String everyLine = "";
        try {
            List<String> allString = new ArrayList<>();
            while ((line = br.readLine()) != null)  //读取到的内容给line变量
            {
                everyLine = line;
                System.out.println(everyLine);
                allString.add(everyLine);
            }
            System.out.println("csv表格中所有行数：" + allString.size());
            if (allString.size() > 1) {
                returnList = new ArrayList<>();
                for (int i = 1; i < allString.size(); i++) {
                    String[] lineData = allString.get(i).split(",");
                    returnList.add(new TemplateBean(lineData[0], lineData[1], lineData[2], lineData[3], lineData[4], lineData[5], lineData[6]));

                }
            }

        } catch (IOException e)

        {
            e.printStackTrace();
        }
        return returnList;

    }

    public static void main(String[] args) {
        CvsHelper.read("");
    }


}
